home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / communic / serus221 / serious.doc < prev    next >
Encoding:
Text File  |  1990-09-01  |  17.1 KB  |  445 lines

  1.  
  2.                                                                    page 1
  3.  
  4.  
  5.  
  6.  
  7.  
  8.               ----------- SERIOUS Users Guide -----------
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.        SERIOUS version 2.21 -- serial communications device driver
  20.        Copyright (c) 1989,1990 by  Norman J. Goldstein
  21.                                    132 Powell Street
  22.                                    Vancouver BC
  23.                                    Canada  V6A 1G1
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.        This software is distributed under the Shareware concept.
  35.  
  36.        - You are encouraged to copy and distribute the file  SERUS221.ZIP ;
  37.          in its original, unmodified form only.
  38.  
  39.        - No fee is to be charged for the software, other than the actual
  40.          cost of copying and distribution.
  41.  
  42.        - If you end up using  SERIOUS , on other than an evaluation basis,
  43.          you are obliged to send in a registration fee to the copyright owner.
  44.          The last section of this document has details on this.
  45.  
  46.        The copyright owner is not liable for damages of any kind resulting
  47.        from the use of this software.
  48.  
  49.                                                                    page 2
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.                        Contents
  57.  
  58.  
  59.  
  60.        Section                                  Page
  61.  
  62.           1     Introduction                      3
  63.  
  64.           2     How  SERIOUS  works               3
  65.  
  66.           3     Function specifications           4
  67.  
  68.           4     Obtaining the entry address       7
  69.  
  70.           5     The inner workings                8
  71.  
  72.           6     Revisions (future and past)       8
  73.  
  74.           7     Registration                      9
  75.  
  76.  
  77.  
  78.                                                                    page 3
  79.  
  80.        Section 1 -- Introduction
  81.  
  82.        SERIOUS is a device driver for the serial port of the IBM PC and
  83.        compatible computers.  It is not a communications program.  It
  84.        does provide the tools to write your own communications program.
  85.        There are, of course,  BIOS and DOS routines for serial com-
  86.        munications, but these are weak, and are not used in serious
  87.        programs.  The  SERIOUS  device driver is intended to fill this
  88.        gap.
  89.  
  90.  
  91.        Section 2 -- How  SERIOUS  works.
  92.  
  93.        The program is a DOS installable device driver.  The syntax for its
  94.        entry in the config.sys file is
  95.  
  96.        device=serious.sys  [name]  [ord]
  97.  
  98.        The 2 parameters  name  and  ord  are optional, and may be placed
  99.        in any order, separated by at least 1 space.
  100.  
  101.        name -- This is the file name by which DOS will recognize the
  102.                installed driver.  The default name is  SERIOUS0 . The 1st
  103.                character must not be a digit.  Otherwise, the usual DOS
  104.                file naming conventions apply; in particular, the name must
  105.                be at most 8 characters.
  106.  
  107.        ord -- The driver may be configured to contain a buffer in
  108.               which to place incoming characters.  The default is that
  109.               there be no such buffer.  If  ord  is a number between
  110.               1 and 16 , then the driver will contain such a buffer.
  111.               Function 0 (open) of section 3  explains how users may
  112.               supply their own buffer for the driver to use.
  113.  
  114.               The buffer has length  2  to the power of the order.  The
  115.               highest allowable order is  16 , which would give the buffer
  116.               the size of a complete segment -- 64K bytes. The smallest
  117.               allowable order is  1 , creating a meagre  2  byte buffer.
  118.  
  119.               Two advantages to creating and using a default buffer within
  120.               the driver are 1) Less work to later open and use the driver,
  121.               and 2) The buffer remains in RAM even if the application
  122.               program is terminated; this is a convenient way for the driver
  123.               to be reaccessed without any incoming characters having been
  124.               lost, assuming that the terminated program did not close
  125.               the driver.
  126.  
  127.               The disadvantage to creating a default buffer within the
  128.               driver is that it may not be deallocated.  The driver
  129.               code occupies less than  1300  bytes in RAM; having a 2K
  130.               buffer would more than double the RAM being used.
  131.  
  132.  
  133.        The driver contains 5 functions, which may be accessed by the
  134.        applications program.  They are described in the next section.
  135.  
  136.  
  137.                                                                    page 4
  138.  
  139.        Section 3 -- Function specifications
  140.  
  141.        The functions are accessed by the application filling CPU registers
  142.        with appropriate values, and then performing a far call to the
  143.        entry address of  SERIOUS .  The way to obtain the entry address
  144.        is explained in section 4 .  Examples are in the file  serface.c ,
  145.        which contains routines for interfacing with  Turbo C .  These
  146.        examples also illustrate how to construct an assembler interface
  147.        to  SERIOUS .  The file  serdemo.c  is a Turbo C example of an
  148.        application using the interface routines of  serface.c  ; it is a
  149.        dumb terminal.
  150.  
  151.        Every function has the following in common.
  152.  
  153.        Input:   bx = function number.
  154.  
  155.        Returns  bx = error code.
  156.                 A value of  0  indicates no error.
  157.  
  158.        The file  serface.h  defines the numeric values of
  159.        all the error codes.
  160.  
  161.        ------------------------------------------------------------------
  162.        Function 0: Open
  163.  
  164.        Purpose: Inform the driver of the user's configuration, and set up
  165.                 the hardware interrupt routines.
  166.  
  167.        Input:   bx = 0 .
  168.                 ax = base port number of the serial chip.
  169.                 ch = interrupt request number (IRQ) of the serial chip.
  170.  
  171.                 cl = order of the user supplied input buffer.
  172.                 es = segment of the user supplied input buffer.
  173.                 di = offset of the user supplied input buffer.
  174.  
  175.           The 'order' and purpose of the input buffer is described in
  176.           section 2 . A reasonable order is  10 , for a buffer of  1K .
  177.           At  1200 baud, a continuous input stream from the serial port would
  178.           fill up a  1K  buffer in about 10 seconds.  A special case is
  179.           entering a value of  0  for the order.  This informs the driver to
  180.           use the default buffer, which is contained within the driver.  The
  181.           size of this default buffer is determined at installation as a
  182.           command paramater in the config.sys file, as explained in section 2 .
  183.  
  184.           If  port  is specified as  0 , then this function  merely reports
  185.           whether the driver is currnetly open.  No other input information
  186.           is used, in this case.
  187.  
  188.        Return errors: ERR_Active   - driver was already open.
  189.                       ERR_BadOrder - the  order  is not in the allowable
  190.                                      range of between  1  and  16 , or
  191.                       neither a default nor a user-defined buffer was
  192.                       specified.
  193.                       ERR_BadIrq    - The Interrupt Request number is
  194.                                       not between  0  and  15 .
  195.                       ERR_NotActive - this is possible, if  port  is
  196.                                       specified as  0 .
  197.        ------------------------------------------------------------------
  198.  
  199.                                                                    page 5
  200.  
  201.        ------------------------------------------------------------------
  202.        Function 1: SetParms
  203.  
  204.        Purpose: Set the transmission parameters.
  205.  
  206.        Input:   bx = 1 .
  207.                 ax = baud.
  208.                 ch = stop , cl = data.
  209.                 dx = parity.
  210.  
  211.          baud = rate of transmission, between  2  and  65,535
  212.                 bits/second.  Some common values are  300 , 1200  and
  213.                 2400 .  The driver has been tested at  9600 , using a
  214.                 hardwire connection to a network.
  215.  
  216.          data = the number of data bits in each character,
  217.                 between  5  and  8 .  Common values are  7  and  8 .
  218.  
  219.          stop = the number of stop bits, either  1  or  2 . (Actually,
  220.                 for  data  of length  5 , only  1 1/2  stop bits are
  221.                 generated when  stop  is specified as  2 .)
  222.  
  223.          parity is the code to specify the type of parity generated.
  224.                 0,2,4,6: no parity bit.
  225.                       1: odd parity.
  226.                       3: even parity.
  227.                       5: mark parity (Parity bit = 1).
  228.                       7: space parity (Parity bit = 0).
  229.  
  230.        When  SERIOUS  is opened, the default paramater settings are
  231.        1200 baud with 8 data bits, 1 stop bit and no parity.
  232.  
  233.        Return errors: ERR_BadData , ERR_BadStop , ERR_BadParity , or
  234.                       ERR_BadBaud  indicates the specified parameter is
  235.                       out of range.
  236.        ------------------------------------------------------------------
  237.  
  238.  
  239.        ------------------------------------------------------------------
  240.        Function 2: Close
  241.  
  242.        Purpose: Disable the UART, and restore the hardware interrupt
  243.                 vectors to their values before the previous call to
  244.                 Open .  It is important to close  SERIOUS  before
  245.                 deallocating the input buffer.  Otherwise, characters might
  246.                 be written to the old location of the input buffer!
  247.  
  248.        Input    bx = 2 .
  249.  
  250.        Return errors: ERR_NotActive - driver was not open.
  251.        ------------------------------------------------------------------
  252.  
  253.                                                                    page 6
  254.  
  255.        ------------------------------------------------------------------
  256.        Function 3: SendChar
  257.  
  258.        Purpose: Send a character out through the serial port.
  259.  
  260.        Input al = character to be sent.
  261.              bx = 3 .
  262.  
  263.        Return errors: ERR_UARTsleeps - UART is not responding.
  264.        ------------------------------------------------------------------
  265.  
  266.        ------------------------------------------------------------------
  267.        Function 4: RecvChar
  268.  
  269.        Purpose: Receive a character from the serial port.
  270.  
  271.        Inpput:   bx = 4 .
  272.  
  273.        Output:  ax = the next character (ah=0), if there is one, or
  274.                 ax = -1 , if there is no character.
  275.  
  276.        Return errors: none
  277.        ------------------------------------------------------------------
  278.  
  279.        ------------------------------------------------------------------
  280.        Function 5: SetMode
  281.  
  282.        Purpose: Specify which interrupts to activate on the UART .
  283.  
  284.        Inpput:   bx = 5 .
  285.                  al = interrupt mask.
  286.                       A bit is set if the interrupt is to be active.
  287.                       bit 0 -- Received data.
  288.                           1 -- Transmitter holding register empty.
  289.                           2 -- Line error.
  290.                           3 -- Modem status change.
  291.  
  292.        The driver routines for reception and transmition require that
  293.        bits 0 and 1 be set.  When the driver is opened, these are the
  294.        only set bits in the mask.
  295.  
  296.        Bits 2 and 3 are useful for debugging.  They have the following
  297.        effect, when the appropriate bit is set.
  298.  
  299.        When a line error is detected, the byte  ^L  is inserted into the
  300.        input stream, followed by the byte content of the Line Status Register
  301.        of the UART .  The relevant bits of this register are described.
  302.        Bit   Meaning when set:
  303.         1 -- Overrun. A received character was overwritten before being read.
  304.         2 -- Parity. A wrong parity bit was received.
  305.         3 -- Framing. A stop bit was not received where expected.
  306.         4 -- Break interrupt.
  307.  
  308.  
  309.                                                                    page 7
  310.        cont Function 5 -- SetMode
  311.  
  312.        When a modem status change is detected, the byte  ^S  is inserted into
  313.        the input stream, followed by the byte content of the Modem Status
  314.        Register of the UART.  The bits of this register are described.
  315.        Bit   Meaning when set:
  316.         0 -- Change in "Clear To Send" .
  317.         1 -- Change in "Data Set Ready" .
  318.         2 -- A ring has just completed.
  319.         3 -- Change in "Data Carrier Detect" .
  320.         4 -- "Clear To Send" .
  321.         5 -- "Data Set Ready" .
  322.         6 -- Ring indicator.
  323.         7 -- "Data Carrier Detect" .
  324.  
  325.        When  ^L  or  ^S  is being used in this special fashion, and is
  326.        received through the serial port, the driver preceeds it  by the
  327.        backslash character  '\' ;  should  '\'  be received, it too is
  328.        preceeded by a backslash!  In other words, the backslash is used
  329.        as an escape character, to denote that the next character is to be
  330.        taken literally.  These complications are introduced only if either
  331.        bits 2 or 3 is set in the interrupt mask; otherwise all characters in
  332.        the input stream have been actually received through the serial port.
  333.  
  334.        Return errors: none
  335.        ------------------------------------------------------------------
  336.  
  337.  
  338.        Section 4 -- Obtaining the entry address
  339.  
  340.        In the earlier versions of  SERIOUS , this was an awkward
  341.        procedure, as the driver was implemented as a TSR .  Not so,
  342.        any more!
  343.  
  344.        The steps outlined in this section are implemented in the
  345.        function  SetEntryAddress()  in the file  serface.c .
  346.  
  347.        The default device name for the driver is  SERIOUS0 , although
  348.        this may be changed at installation, as explained in section 2 .
  349.        This device must be opened, as any regular file, to obtain a
  350.        descriptor from  DOS .  This descriptor is used to perform an
  351.        "i/o control" read from the driver; this places the entry address
  352.        into a user supplied variable i.e. into a 4 byte buffer.
  353.  
  354.  
  355.                                                                    page 8
  356.  
  357.        Section 5 -- The inner workings
  358.  
  359.        The PC serial communications chip is called a UART (Universal
  360.        Asynchronous Receiver Transmitter).  As characters are received by
  361.        the UART through the serial port, SERIOUS  automatically places them
  362.        into an input buffer (specified by the user), using the hardware
  363.        interrupt system of the UART.  This buffer is implemented as a
  364.        circular buffer.  As soon as wrap-around occurs, the buffer
  365.        becomes 'empty'. The user must read characters from the input
  366.        buffer sufficiently often to ensure this does not happen. This is
  367.        not difficult.  A  1K  buffer takes about 10 seconds to fill up at
  368.        1200 baud.  There is plenty of time for the CPU to process
  369.        the characters.
  370.  
  371.        When open, the driver intercepts 3 interrupts:
  372.  
  373.        0Ch -- UART interrupt, mentioned above.
  374.        1Ch -- Clock interrupt, for timings.
  375.        23h -- DOS break (^C) interrupt.  The driver is automatically
  376.               closed.  This means that it is safe, as far as SERIOUS is
  377.               concerned, to terminate your application using  ^C .
  378.  
  379.  
  380.        Section 6 -- Revisions (future and past)
  381.  
  382.        Some possible enhancements are:
  383.  
  384.        - Allow changing the input buffer.
  385.          (Now, SERIOUS must first be closed, and then opened to change
  386.           the size or location of the input buffer.)
  387.  
  388.        - Specify/change an output buffer, at any time.  This allows for
  389.          smoother transmission;  the interrupt system of the UART would,
  390.          more completely, handle the sending of characters out through
  391.          the serial port.
  392.          (Now, there is no output buffer, and spin waits are used until
  393.           the UART is ready to send the next character.)
  394.  
  395.        - Support the break interrupt facility of the UART.
  396.  
  397.  
  398.        Revision history:
  399.  
  400.        This is off to a late start.  Better late than never!
  401.  
  402.        23 Aug 1990: Version 2.21 -- Bug fix.  Now ports other than COM1
  403.                     can actually be used.
  404.  
  405.  
  406.  
  407.  
  408.                                                                    page 9
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.        Section 7 -- Registration
  416.  
  417.        Single users are asked to send $20 to the address on the cover page
  418.        of this document.  For evnironments with multiple machines, please
  419.        contact me to arrange an agreement.
  420.  
  421.        In any event, I would like to hear your comments about this software.
  422.        For registered users, I certainly intend to give detailed responses,
  423.        as well as early update information.
  424.  
  425.  
  426.  
  427.         ----------------------------------------------------------------
  428.  
  429.  
  430.         IBM  is a registered trademark of
  431.              International Business Machines Corporation .
  432.  
  433.         Turbo C  is a registered trademark of  Borland International .
  434.  
  435.  
  436.  
  437.         I made heavy use of the document
  438.  
  439.         "NS16450/INS8250A/NS16C450/INS82C50A
  440.          Asynchronous Communications Element" , Feb 1985
  441.          by National Semiconductor
  442.  
  443.         which I obtained, along with other helpful information, from
  444.         Hamilton Avnet Electronics  in  Burnaby, BC .
  445.